<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/wesite/view/common/base.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>用户信息</title>
    <%@ include file="/wesite/view/common/common.jsp"%>
    <style type="text/css">
        .my-base-info.hide .box ul li a span{
            color: #333;
        }
        .my-base-info .box ul li:last-child{
            border-bottom: none;
        }
        .my-base-info .box ul a:last-child li{
            border-bottom: none;
        }
    </style>
</head>
<body>
<div class="my-base-info" id="vip">
    <div class="avatar box">
        <input type="hidden" name="id" value="${user.id}">
        <label><i class="ico"></i><span>头像</span></label>
        <div class="rg">
            <a href="javascript:;" id="upheadbtn" class="rg">
            <span id="uheadimg">
                <c:if test="${not empty user.photo}">
                    <img src="<%=getRandomFileserver()%>${user.photo}" />
                </c:if>
                <c:if test="${empty user.photo}">
                    <img src="${webctx }/images/uhead.jpg" />
                </c:if>
            </span>
        </div>
        </a>
    </div>
    <div class="box mt20 icon-my-usweinfo">
        <ul>
            <li>
                <label><i class="ico username"></i><span>昵称</span></label>
                <a href="javascript:upck()"> <input type="text" value="${user.nickname }"  readonly=""></a>

            </li>
            <li>
                <label><i class="ico account"></i><span>用户名</span></label>
                <input type="text" value="${user.loginname }" readonly="">
            </li>
            <li>
                <label><i class="ico phone"></i><span>手机号码</span></label>
                <input type="text" value="${user.phone }" readonly="">
            </li>
            <li class="addr-box">
                <label><i class="ico addr"></i><span>收货地址</span></label>
                <div class="addr-con">${address.shen }${address.shi }${address.qu }${address.address }</div>
            </li>
        </ul>
        <div class="my-base-info mt20" id="account">
            <div class="box">
                <ul>
                    <c:if test="${not empty user.loginphone}" >
                        <a href="${ctx}/we/user/showchangephone">
                            <li>
                                <label><i class="ico phone g-phone"></i>
                                    <span>修改绑定手机号码</span>
                                    <span class="arrow-r"></span>
                                </label>
                            </li>
                        </a>
                    </c:if>
                    <c:if test="${empty user.loginphone}">
                        <a href="${ctx}/we/user/weshowBindPhone">
                            <li>
                                <label>
                                    <i class="ico phone"></i>
                                    <span>绑定手机</span>
                                    <span class="arrow-r"></span>
                                </label>
                            </li>
                        </a>
                    </c:if>
                    <a href="${ctx}/we/user/settpassword">
                        <li>
                            <label>
                                <i class="ico password-num"></i>
                                <span>修改密码</span>
                                <span class="arrow-r"></span>
                            </label>
                        </li>
                    </a>
                </ul>
            </div>
        </div>
    </div>
    <div class="h98"></div>
    <div class="h98"></div>
    <div class="exit-login">
        <a href="javascript:loginout(this);" class="curColor"><span>退出登录</span></a>
    </div>
</div>
</body>
<script src="${webctx}/script/upload.js"></script>
<script src="${webctx}/script/plupload.full.min.js"></script>
<script src="${webctx}/script/aui-toast.js"></script>
<script type="text/javascript">
    var toast = new auiToast({});
    function showToastLoading(msg){
        toast.loading({
            title: msg
        });
    }
    function hideToastLoading(){
        toast.hide();
    }
</script>
<script type="text/javascript">
    apiready = function(){
        api.parseTapmode();
    }
    //退出
    var isLogouting = false;
    function loginout(_this){
        if(isLogouting){
            return false;
        } else {
            isLogouting = true;
        }
        showToastLoading("正在退出...");
        $w.clearLoginUser();
        $w.httpRequest({
            url:ctx+"/we/user/weloginout",
            data:{},
            ok:function(ret){
                window.location.href=ctx+"/we/user/login";
                hideToastLoading();
            }
        })
    }
    function toskip() {
        $("#vip").hide();
        $("#account").show();
    }
    var uploader;
    $(function(){
        //setLeftCur("zhugl");
        //lo();
        var plparm={
            runtimes : 'html5,flash,silverlight,html4',
            browse_button :'upheadbtn',
            url : '${ctx}/upload/UploadPage@uploadPhoto.page?dir=head&tosave=false',
            flash_swf_url : '${ctx}/plugins/plupload2/Moxie2.swf',
            silverlight_xap_url : '${ctx}/plugins/plupload2/Moxie.xap',
            multi_selection:false,
            filters: {
                max_file_size : '500kb',
                prevent_duplicates :false, //不允许选取重复文件
                mime_types : [{ title : "图片文件", extensions : "jpg,png" }] //只允许上传图片文件
            },
            init:{
                FilesAdded: function(up, files) {
                    uploader.start();
                    previewImageOne(files[0],function(imgsrc){
                        $("#uheadimg img").attr("src",imgsrc);
                    })
                },
                FileUploaded:function(up,file,responseObject){
                    var re=jQuery.parseJSON(responseObject.response);
                    $w.httpRequest({
                        url:"${ctx}/we/user/weeditsave",
                        data:{"photo":re.url.replace(re.basepath,"")},
                        ok:function(ret){
                        }
                    })
                },
                Error:function(up, err){
                    if(err.code!="-602"){
                        if(err.code=="-600") {
                            toast.fail({
                                title : "图片大小不能超过500kb",
                                duration : 1000
                            })
                        }else{
                            toast.fail({
                                title : err.code+"-"+err.message,
                                duration : 1000
                            })
                        }
                    }
                    return false;
                }
            }
        };
        $oss.setUpDir("userhead");
        uploader=$oss.initUpload(plparm);
    })
    function previewImageOne(file,callback){
        if(!file || !/image\//.test(file.type)) return;
        if(file.type=='image/gif'){
            var fr2 = new mOxie.FileReader();
            fr2.onload = function(){
                callback(fr2.result);
                fr2.destroy();
                fr2 = null;
            }
            fr2.readAsDataURL(file.getSource());
        }else{
            var preloader = new mOxie.Image();
            preloader.onload = function() {
                //preloader.downsize( 300, 300 );
                var imgsrc = preloader.type=='image/jpeg' ? preloader.getAsDataURL('image/jpeg',80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
                callback && callback(imgsrc);
                preloader.destroy();
                preloader = null;
            };
            preloader.load( file.getSource() );
        }
    }
    function lo() {
        window.location.href="${ctx}/we/user/wehome";
    }
    function upck(){
        var userid = $("[name='id']").val();
        window.location.href="${ctx}/we/user/nickname1";
    }
</script>
</html>